package com.fs.service.impl;

import com.fs.Utils.CusAccessObjectUtil;
import com.fs.service.PreGlobalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author ：hyq
 * @date ：Created in 2020/6/7 14:13
 * @description：
 * @modified By：
 */
@Service
@Slf4j
@RefreshScope
public class PreGlobalServiceImpl implements PreGlobalService {



    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        return null;
    }

    @Override
    public long printSub(long start) {
        long sub = System.currentTimeMillis() - start;
        return sub;
    }

    @Override
    public void setUserIpAddress(ServerHttpRequest request) {
        // 存在代理情况下获取IP
        String ip = CusAccessObjectUtil.getIpAddress(request);
        request.mutate().header("userIpAddress", ip);
    }
}
